package test.designmode.future;

import test.datetime.DateUtil;

/**
 * Created by linshuo on 2018/3/4.
 * <p>
 * - Future = 代理 + 异步;
 * - Future模式的优势在于能充分利用等待时间, 在等待(request)执行期间我能去摸鱼, 摸完鱼再看下结果返回了没;
 */
public class Main {
    public static void main(String[] args) {
        FutureClient client = new FutureClient();
        Data result = client.request("name");  // 异步请求
        doOtherThing();
        String responseContent = result.getResult(); // 查询结果,若结果还没出则会阻塞直至拿到结果
        System.out.println(responseContent);
    }

    private static void doOtherThing() {
        try {
            System.out.println("摸鱼中... ...");
            Thread.sleep(500);
            System.out.println("摸完了");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
